<?php
session_start();
if (isset($_SESSION["id"]))
    header("location:index.php");
?>
<link rel="stylesheet" type="text/css" href="public/css/css-login.css">
<div id="khung">
    <form action="login.php" method="POST">
        <div id="login">
            <input type="text" name="userName" id="userName" placeholder="Username">
            <input type="password" name="passWord" id="passWord"  placeholder="Password">
            <input type="submit" name="submit" value="Login"/>
        </div>
    </form>
</div>
<?php require_once 'data/users.php'; ?>
<?php if (isset($_POST["submit"])) { ?>
    <?php $index = 0; ?>
    <?php for ($i = 0; $i < count($users); $i++): ?>
        <?php if (strcmp($users[$index]["username"], $_POST["userName"]) == 0 && strcmp($users[$index]["password"], $_POST["passWord"]) == 0) { ?>
            <?php $_SESSION["id"] = $users[$index]["id"]; ?>
            <?php header("location:index.php"); ?>
        <?php } ?>
        <?php $index++; ?>
    <?php endfor; ?>
<?php } ?>
